```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>MyBatis事务管理机制深度解析 | 技术小馆</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.6;
            background-color: #f9f9f9;
        }
        .hero {
            background: linear-gradient(135deg, #2c3e50 0%, #3498db 100%);
            color: white;
        }
        .code-block {
            background-color: #282c34;
            border-radius: 8px;
            padding: 1.5rem;
            position: relative;
        }
        .code-block pre {
            margin: 0;
            font-family: 'Courier New', Courier, monospace;
            color: #abb2bf;
            overflow-x: auto;
        }
        .code-block .language {
            position: absolute;
            top: 0;
            right: 0;
            background: #1e2227;
            color: #abb2bf;
            padding: 0.25rem 0.75rem;
            border-bottom-left-radius: 8px;
            font-size: 0.8rem;
        }
        .section-card {
            transition: transform 0.3s ease, box-shadow 0.3s ease;
        }
        .section-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
        }
        .highlight {
            background: linear-gradient(90deg, rgba(255,255,255,0) 50%, #e3f2fd 50%);
            background-size: 200% 100%;
            background-position: 100% 0;
            transition: background-position 0.3s ease;
        }
        .highlight:hover {
            background-position: 0 0;
        }
        .drop-cap:first-letter {
            float: left;
            font-size: 3.5rem;
            line-height: 3rem;
            padding-right: 0.5rem;
            font-weight: bold;
            color: #2c3e50;
        }
        .footer {
            background-color: #1a1a1a;
        }
    </style>
</head>
<body class="min-h-screen">
    <!-- Hero Section -->
    <section class="hero py-20 px-4 md:px-0">
        <div class="container mx-auto max-w-5xl text-center">
            <div class="flex justify-center mb-6">
                <span class="px-4 py-1 bg-white bg-opacity-20 rounded-full text-sm font-medium">技术深度解析</span>
            </div>
            <h1 class="text-4xl md:text-5xl font-bold mb-6 font-serif">MyBatis事务管理机制</h1>
            <p class="text-xl md:text-2xl max-w-3xl mx-auto opacity-90 mb-8">
                探索MyBatis框架中确保数据库操作一致性和可靠性的关键机制
            </p>
            <div class="flex justify-center space-x-4">
                <a href="#overview" class="px-6 py-3 bg-white bg-opacity-10 hover:bg-opacity-20 rounded-lg transition duration-300">
                    <i class="fas fa-book-open mr-2"></i>开始阅读
                </a>
                <a href="#diagram" class="px-6 py-3 bg-blue-600 hover:bg-blue-700 rounded-lg transition duration-300">
                    <i class="fas fa-project-diagram mr-2"></i>原理图解
                </a>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto max-w-5xl px-4 md:px-0 py-12">
        <!-- Overview Section -->
        <section id="overview" class="mb-16">
            <div class="bg-white rounded-xl shadow-md overflow-hidden p-8 section-card">
                <div class="flex items-start mb-8">
                    <div class="bg-blue-100 p-3 rounded-lg mr-4">
                        <i class="fas fa-cogs text-blue-600 text-2xl"></i>
                    </div>
                    <div>
                        <h2 class="text-2xl font-bold mb-2">事务管理概述</h2>
                        <p class="text-gray-600">MyBatis事务管理的核心概念与设计哲学</p>
                    </div>
                </div>
                <div class="space-y-6">
                    <p class="drop-cap">
                        在MyBatis框架中，事务管理是确保数据库操作一致性和可靠性的关键机制。MyBatis支持通过不同的方式进行事务管理，包括JDBC、Spring等。事务管理的核心目标是提供对多个SQL操作的原子性处理。
                    </p>
                    <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mt-8">
                        <div class="bg-blue-50 p-6 rounded-lg">
                            <div class="flex items-center mb-3">
                                <div class="bg-blue-100 p-2 rounded-full mr-3">
                                    <i class="fas fa-shield-alt text-blue-600"></i>
                                </div>
                                <h3 class="font-bold">ACID特性保障</h3>
                            </div>
                            <p class="text-gray-700">MyBatis事务管理确保数据库操作的原子性(Atomicity)、一致性(Consistency)、隔离性(Isolation)和持久性(Durability)。</p>
                        </div>
                        <div class="bg-green-50 p-6 rounded-lg">
                            <div class="flex items-center mb-3">
                                <div class="bg-green-100 p-2 rounded-full mr-3">
                                    <i class="fas fa-exchange-alt text-green-600"></i>
                                </div>
                                <h3 class="font-bold">灵活集成支持</h3>
                            </div>
                            <p class="text-gray-700">MyBatis既支持原生JDBC事务管理，也能与Spring等框架的事务管理机制无缝集成。</p>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Architecture Section -->
        <section id="architecture" class="mb-16">
            <div class="bg-white rounded-xl shadow-md overflow-hidden p-8 section-card">
                <div class="flex items-start mb-8">
                    <div class="bg-purple-100 p-3 rounded-lg mr-4">
                        <i class="fas fa-sitemap text-purple-600 text-2xl"></i>
                    </div>
                    <div>
                        <h2 class="text-2xl font-bold mb-2">1. 事务管理的基本架构</h2>
                        <p class="text-gray-600">Transaction接口与TransactionFactory的设计与实现</p>
                    </div>
                </div>
                <div class="space-y-6">
                    <p>
                        MyBatis的事务管理是基于<code class="highlight px-1 py-0.5 rounded">Transaction</code>接口和<code class="highlight px-1 py-0.5 rounded">TransactionFactory</code>的，<code class="highlight px-1 py-0.5 rounded">Transaction</code>接口定义了事务的基本操作方法，如<code class="highlight px-1 py-0.5 rounded">commit</code>、<code class="highlight px-1 py-0.5 rounded">rollback</code>和<code class="highlight px-1 py-0.5 rounded">close</code>等。MyBatis通过不同的<code class="highlight px-1 py-0.5 rounded">TransactionFactory</code>来根据不同的环境创建事务实例，例如JDBC事务、Spring事务等。
                    </p>
                    <p>
                        <code class="highlight px-1 py-0.5 rounded">Transaction</code>接口包含了对事务的基本操作，包括获取数据库连接、提交事务、回滚事务等。
                    </p>
                    <p>
                        MyBatis通过<code class="highlight px-1 py-0.5 rounded">TransactionFactory</code>来根据配置选择合适的事务管理实现：
                    </p>
                    
                    <div class="code-block mt-6">
                        <span class="language">Java</span>
                        <pre><code>public interface TransactionFactory {
    Transaction newTransaction(DataSource dataSource, 
                             TransactionIsolationLevel level, 
                             boolean autoCommit);
}</code></pre>
                    </div>
                    
                    <p>
                        <code class="highlight px-1 py-0.5 rounded">TransactionFactory</code>的<code class="highlight px-1 py-0.5 rounded">newTransaction()</code>方法根据数据源、事务隔离级别和自动提交设置来创建具体的<code class="highlight px-1 py-0.5 rounded">Transaction</code>对象。
                    </p>
                </div>
            </div>
        </section>

        <!-- JdbcTransaction Section -->
        <section id="jdbc-transaction" class="mb-16">
            <div class="bg-white rounded-xl shadow-md overflow-hidden p-8 section-card">
                <div class="flex items-start mb-8">
                    <div class="bg-orange-100 p-3 rounded-lg mr-4">
                        <i class="fas fa-database text-orange-600 text-2xl"></i>
                    </div>
                    <div>
                        <h2 class="text-2xl font-bold mb-2">2. JdbcTransaction的实现</h2>
                        <p class="text-gray-600">MyBatis默认的JDBC事务实现细节</p>
                    </div>
                </div>
                <div class="space-y-6">
                    <p>
                        <code class="highlight px-1 py-0.5 rounded">JdbcTransaction</code>是MyBatis默认的事务实现类，负责在JDBC环境下管理事务。它通过JDBC的<code class="highlight px-1 py-0.5 rounded">Connection</code>对象来执行事务操作。
                    </p>
                    
                    <div class="code-block mt-6">
                        <span class="language">Java</span>
                        <pre><code>public class JdbcTransaction implements Transaction {
    private final Connection connection;
    private boolean autoCommit;

    public JdbcTransaction(Connection connection, boolean autoCommit) {
        this.connection = connection;
        this.autoCommit = autoCommit;
    }

    @Override
    public Connection getConnection() throws SQLException {
        return connection;
    }

    @Override
    public void commit() throws SQLException {
        if (!autoCommit) {
            connection.commit();  // 提交事务
        }
    }

    @Override
    public void rollback() throws SQLException {
        if (!autoCommit) {
            connection.rollback();  // 回滚事务
        }
    }

    @Override
    public void close() throws SQLException {
        if (connection != null) {
            connection.close();  // 关闭连接
        }
    }
}</code></pre>
                    </div>
                    
                    <ul class="list-disc pl-6 space-y-2">
                        <li><code class="highlight px-1 py-0.5 rounded">JdbcTransaction</code>会使用传入的<code class="highlight px-1 py-0.5 rounded">Connection</code>对象来管理事务。</li>
                        <li><code class="highlight px-1 py-0.5 rounded">commit()</code>方法会提交事务，<code class="highlight px-1 py-0.5 rounded">rollback()</code>方法会回滚事务，<code class="highlight px-1 py-0.5 rounded">close()</code>方法会关闭连接。</li>
                    </ul>
                    
                    <p>
                        在MyBatis中，<code class="highlight px-1 py-0.5 rounded">JdbcTransaction</code>通常由<code class="highlight px-1 py-0.5 rounded">TransactionFactory</code>创建和管理。<code class="highlight px-1 py-0.5 rounded">SqlSession</code>会通过<code class="highlight px-1 py-0.5 rounded">Transaction</code>接口与数据库进行交互。
                    </p>
                </div>
            </div>
        </section>

        <!-- SqlSession Section -->
        <section id="sqlsession" class="mb-16">
            <div class="bg-white rounded-xl shadow-md overflow-hidden p-8 section-card">
                <div class="flex items-start mb-8">
                    <div class="bg-teal-100 p-3 rounded-lg mr-4">
                        <i class="fas fa-terminal text-teal-600 text-2xl"></i>
                    </div>
                    <div>
                        <h2 class="text-2xl font-bold mb-2">3. SqlSession中的事务控制</h2>
                        <p class="text-gray-600">MyBatis核心接口SqlSession的事务管理机制</p>
                    </div>
                </div>
                <div class="space-y-6">
                    <p>
                        <code class="highlight px-1 py-0.5 rounded">SqlSession</code>是MyBatis的核心接口之一，它封装了数据库的操作并提供了事务控制。<code class="highlight px-1 py-0.5 rounded">SqlSession</code>管理着事务的生命周期，包括事务的开启、提交、回滚和关闭。
                    </p>
                    
                    <div class="code-block mt-6">
                        <span class="language">Java</span>
                        <pre><code>public interface SqlSession {
    void commit();
    void rollback();
    void close();
}</code></pre>
                    </div>
                    
                    <ul class="list-disc pl-6 space-y-2">
                        <li><code class="highlight px-1 py-0.5 rounded">SqlSession</code>提供了<code class="highlight px-1 py-0.5 rounded">commit()</code>、<code class="highlight px-1 py-0.5 rounded">rollback()</code>和<code class="highlight px-1 py-0.5 rounded">close()</code>方法，用于手动控制事务的提交、回滚和关闭。</li>
                        <li>在执行SQL操作时，<code class="highlight px-1 py-0.5 rounded">SqlSession</code>会根据事务状态决定是否提交或回滚事务。</li>
                    </ul>
                    
                    <p>
                        <code class="highlight px-1 py-0.5 rounded">SqlSession</code>的实现类<code class="highlight px-1 py-0.5 rounded">DefaultSqlSession</code>的部分实现如下：
                    </p>
                    
                    <div class="code-block mt-6">
                        <span class="language">Java</span>
                        <pre><code>public class DefaultSqlSession implements SqlSession {
    private final Executor executor;
    private final Transaction transaction;

    public DefaultSqlSession(Transaction transaction, Executor executor) {
        this.transaction = transaction;
        this.executor = executor;
    }

    @Override
    public void commit() {
        try {
            transaction.commit();  // 提交事务
        } catch (SQLException e) {
            rollback();
            throw new RuntimeException("Failed to commit transaction", e);
        }
    }

    @Override
    public void rollback() {
        try {
            transaction.rollback();  // 回滚事务
        } catch (SQLException e) {
            throw new RuntimeException("Failed to rollback transaction", e);
        }
    }

    @Override
    public void close() {
        try {
            transaction.close();  // 关闭事务
        } catch (SQLException e) {
            throw new RuntimeException("Failed to close transaction", e);
        }
    }
}</code></pre>
                    </div>
                    
                    <p>
                        <code class="highlight px-1 py-0.5 rounded">DefaultSqlSession</code>中，<code class="highlight px-1 py-0.5 rounded">commit()</code>方法会调用<code class="highlight px-1 py-0.5 rounded">transaction.commit()</code>提交事务，<code class="highlight px-1 py-0.5 rounded">rollback()</code>方法会调用<code class="highlight px-1 py-0.5 rounded">transaction.rollback()</code>回滚事务，<code class="highlight px-1 py-0.5 rounded">close()</code>方法会调用<code class="highlight px-1 py-0.5 rounded">transaction.close()</code>关闭事务。
                    </p>
                </div>
            </div>
        </section>

        <!-- TransactionFactory Section -->
        <section id="transaction-factory" class="mb-16">
            <div class="bg-white rounded-xl shadow-md overflow-hidden p-8 section-card">
                <div class="flex items-start mb-8">
                    <div class="bg-indigo-100 p-3 rounded-lg mr-4">
                        <i class="fas fa-industry text-indigo-600 text-2xl"></i>
                    </div>
                    <div>
                        <h2 class="text-2xl font-bold mb-2">4. TransactionFactory的实现与事务的创建</h2>
                        <p class="text-gray-600">事务实例的创建过程与工厂模式应用</p>
                    </div>
                </div>
                <div class="space-y-6">
                    <p>
                        <code class="highlight px-1 py-0.5 rounded">TransactionFactory</code>是MyBatis中负责创建<code class="highlight px-1 py-0.5 rounded">Transaction</code>实例的工厂类。根据配置，MyBatis可以选择不同类型的事务管理实现。
                    </p>
                    
                    <div class="code-block mt-6">
                        <span class="language">Java</span>
                        <pre><code>public class JdbcTransactionFactory implements TransactionFactory {
    @Override
    public Transaction newTransaction(DataSource dataSource, 
                                    TransactionIsolationLevel level, 
                                    boolean autoCommit) {
        try {
            // 创建并返回一个JdbcTransaction实例
            Connection connection = dataSource.getConnection();
            connection.setAutoCommit(autoCommit);
            connection.setTransactionIsolation(level.getLevel());
            return new JdbcTransaction(connection, autoCommit);
        } catch (SQLException e) {
            throw new RuntimeException("Failed to create transaction", e);
        }
    }
}</code></pre>
                    </div>
                    
                    <ul class="list-disc pl-6 space-y-2">
                        <li><code class="highlight px-1 py-0.5 rounded">JdbcTransactionFactory</code>根据传入的数据源、事务隔离级别和自动提交设置来创建<code class="highlight px-1 py-0.5 rounded">JdbcTransaction</code>对象。</li>
                    </ul>
                    
                    <p>
                        在MyBatis中，事务管理的创建通常通过<code class="highlight px-1 py-0.5 rounded">SqlSessionFactory</code>进行，<code class="highlight px-1 py-0.5 rounded">SqlSessionFactory</code>会根据配置文件的设置选择合适的<code class="highlight px-1 py-0.5 rounded">TransactionFactory</code>。
                    </p>
                    
                    <div class="code-block mt-6">
                        <span class="language">Java</span>
                        <pre><code>public class SqlSessionFactoryBuilder {
    public SqlSessionFactory build(Reader reader) {
        // 解析配置文件并创建SqlSessionFactory
        Configuration configuration = new Configuration();
        TransactionFactory transactionFactory = new JdbcTransactionFactory();
        configuration.setTransactionFactory(transactionFactory);
        return new DefaultSqlSessionFactory(configuration);
    }
}</code></pre>
                    </div>
                    
                    <ul class="list-disc pl-6 space-y-2">
                        <li>在<code class="highlight px-1 py-0.5 rounded">SqlSessionFactory</code>的构建过程中，<code class="highlight px-1 py-0.5 rounded">TransactionFactory</code>根据配置文件创建事务实例。</li>
                    </ul>
                </div>
            </div>
        </section>

        <!-- Isolation Levels Section -->
        <section id="isolation" class="mb-16">
            <div class="bg-white rounded-xl shadow-md overflow-hidden p-8 section-card">
                <div class="flex items-start mb-8">
                    <div class="bg-green-100 p-3 rounded-lg mr-4">
                        <i class="fas fa-filter text-green-600 text-2xl"></i>
                    </div>
                    <div>
                        <h2 class="text-2xl font-bold mb-2">5. 事务的传播机制与隔离级别</h2>
                        <p class="text-gray-600">事务行为控制与并发处理策略</p>
                    </div>
                </div>
                <div class="space-y-6">
                    <p>
                        MyBatis本身不直接实现事务的传播机制，但可以与Spring集成，通过Spring的事务管理来实现更复杂的事务行为。Spring的事务传播机制和隔离级别可以与MyBatis的事务一起使用，确保更灵活的事务控制。
                    </p>
                    
                    <ul class="list-disc pl-6 space-y-2">
                        <li><strong>传播机制</strong>：指定当前事务与其他事务之间的关系，常见的传播机制包括<code class="highlight px-1 py-0.5 rounded">REQUIRED</code>（支持当前事务）、<code class="highlight px-1 py-0.5 rounded">REQUIRES_NEW</code>（新建事务）等。</li>
                        <li><strong>隔离级别</strong>：指定一个事务如何与其他事务隔离，常见的隔离级别包括<code class="highlight px-1 py-0.5 rounded">READ_COMMITTED</code>、<code class="highlight px-1 py-0.5 rounded">READ_UNCOMMITTED</code>、<code class="highlight px-1 py-0.5 rounded">REPEATABLE_READ</code>、<code class="highlight px-1 py-0.5 rounded">SERIALIZABLE</code>。</li>
                    </ul>
                    
                    <p>
                        MyBatis通过<code class="highlight px-1 py-0.5 rounded">TransactionIsolationLevel</code>来设置隔离级别：
                    </p>
                    
                    <div class="code-block mt-6">
                        <span class="language">Java</span>
                        <pre><code>public enum TransactionIsolationLevel {
    NONE(Connection.TRANSACTION_NONE),
    READ_COMMITTED(Connection.TRANSACTION_READ_COMMITTED),
    READ_UNCOMMITTED(Connection.TRANSACTION_READ_UNCOMMITTED),
    REPEATABLE_READ(Connection.TRANSACTION_REPEATABLE_READ),
    SERIALIZABLE(Connection.TRANSACTION_SERIALIZABLE);

    private final int level;

    TransactionIsolationLevel(int level) {
        this.level = level;
    }

    public int getLevel() {
        return level;
    }
}</code></pre>
                    </div>
                    
                    <ul class="list-disc pl-6 space-y-2">
                        <li><code class="highlight px-1 py-0.5 rounded">TransactionIsolationLevel</code>枚举定义了不同的事务隔离级别，可以在创建<code class="highlight px-1 py-0.5 rounded">JdbcTransaction</code>时传入。</li>
                    </ul>
                </div>
            </div>
        </section>

        <!-- Spring Integration Section -->
        <section id="spring" class="mb-16">
            <div class="bg-white rounded-xl shadow-md overflow-hidden p-8 section-card">
                <div class="flex items-start mb-8">
                    <div class="bg-yellow-100 p-3 rounded-lg mr-4">
                        <i class="fas fa-leaf text-yellow-600 text-2xl"></i>
                    </div>
                    <div>
                        <h2 class="text-2xl font-bold mb-2">6. MyBatis与Spring的事务管理集成</h2>
                        <p class="text-gray-600">企业级应用中的事务管理方案</p>
                    </div>
                </div>
                <div class="space-y-6">
                    <p>
                        MyBatis可以通过与Spring的集成来实现更复杂的事务管理。Spring的<code class="highlight px-1 py-0.5 rounded">PlatformTransactionManager</code>可以用于控制事务的生命周期和传播行为，MyBatis则通过<code class="highlight px-1 py-0.5 rounded">SqlSessionTemplate</code>来执行SQL操作。
                    </p>
                    
                    <div class="code-block mt-6">
                        <span class="language">Java</span>
                        <pre><code>public class SqlSessionTemplate implements SqlSession {
    private final SqlSessionFactory sqlSessionFactory;

    public SqlSessionTemplate(SqlSessionFactory sqlSessionFactory) {
        this.sqlSessionFactory = sqlSessionFactory;
    }

    @Override
    public void commit() {
        // 委托给Spring事务管理器来管理事务
        // Spring会根据配置管理事务的提交、回滚等操作
    }

    @Override
    public void rollback() {
        // 同上，交由Spring事务管理器处理
    }
}</code></pre>
                    </div>
                    
                    <ul class="list-disc pl-6 space-y-2">
                        <li><code class="highlight px-1 py-0.5 rounded">SqlSessionTemplate</code>是Spring提供的MyBatis的<code class="highlight px-1 py-0.5 rounded">SqlSession</code>实现，它与Spring的事务管理机制无缝集成，通过Spring的<code class="highlight px-1 py-0.5 rounded">TransactionTemplate</code>来控制事务的提交和回滚。</li>
                    </ul>
                </div>
            </div>
        </section>

        <!-- Process Flow Section -->
        <section id="process" class="mb-16">
            <div class="bg-white rounded-xl shadow-md overflow-hidden p-8 section-card">
                <div class="flex items-start mb-8">
                    <div class="bg-red-100 p-3 rounded-lg mr-4">
                        <i class="fas fa-random text-red-600 text-2xl"></i>
                    </div>
                    <div>
                        <h2 class="text-2xl font-bold mb-2">7. 事务的执行流程</h2>
                        <p class="text-gray-600">MyBatis事务管理的完整生命周期</p>
                    </div>
                </div>
                <div class="space-y-6">
                    <p>
                        在MyBatis中，事务管理的执行流程大致如下：
                    </p>
                    
                    <ol class="list-decimal pl-6 space-y-3">
                        <li><strong>创建事务</strong>：<code class="highlight px-1 py-0.5 rounded">SqlSessionFactory</code>通过<code class="highlight px-1 py-0.5 rounded">TransactionFactory</code>创建一个<code class="highlight px-1 py-0.5 rounded">Transaction</code>实例，通常是<code class="highlight px-1 py-0.5 rounded">JdbcTransaction</code>。</li>
                        <li><strong>执行SQL操作</strong>：在<code class="highlight px-1 py-0.5 rounded">SqlSession</code>中，数据库操作会通过<code class="highlight px-1 py-0.5 rounded">Executor</code>执行，同时事务会保持打开状态。</li>
                        <li><strong>提交事务</strong>：当<code class="highlight px-1 py-0.5 rounded">SqlSession.commit()</code>被调用时，<code class="highlight px-1 py-0.5 rounded">JdbcTransaction</code>会提交事务。</li>
                        <li><strong>回滚事务</strong>：如果操作出现异常，<code class="highlight px-1 py-0.5 rounded">SqlSession.rollback()</code>会被调用，<code class="highlight px-1 py-0.5 rounded">JdbcTransaction</code>会回滚事务。</li>
                        <li><strong>关闭事务</strong>：在完成操作后，<code class="highlight px-1 py-0.5 rounded">SqlSession.close()</code>会关闭事务，释放数据库连接。</li>
                    </ol>
                    
                    <!-- Mermaid Diagram -->
                    <div id="diagram" class="mt-10">
                        <div class="flex items-center mb-4">
                            <div class="bg-blue-100 p-2 rounded-full mr-3">
                                <i class="fas fa-project-diagram text-blue-600"></i>
                            </div>
                            <h3 class="text-xl font-bold">MyBatis事务管理流程图</h3>
                        </div>
                        <div class="mermaid">
                            sequenceDiagram
                                participant User
                                participant SqlSession
                                participant Transaction
                                participant Connection
                                
                                User->>SqlSession: 开始事务
                                SqlSession->>TransactionFactory: 创建Transaction实例
                                TransactionFactory->>Transaction: newTransaction()
                                Transaction->>Connection: 获取连接
                                User->>SqlSession: 执行SQL操作
                                SqlSession->>Executor: 执行SQL
                                Executor->>Connection: 执行语句
                                alt 操作成功
                                    User->>SqlSession: commit()
                                    SqlSession->>Transaction: commit()
                                    Transaction->>Connection: commit()
                                else 操作失败
                                    User->>SqlSession: rollback()
                                    SqlSession->>Transaction: rollback()
                                    Transaction->>Connection: rollback()
                                end
                                User->>SqlSession: close()
                                SqlSession->>Transaction: close()
                                Transaction->>Connection: close()
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Summary Section -->
        <section class="mb-16">
            <div class="bg-gradient-to-r from-blue-50 to-indigo-50 rounded-xl shadow-md overflow-hidden p-8">
                <div class="flex items-center mb-6">
                    <div class="bg-blue-600 text-white p-3 rounded-lg mr-4">
                        <i class="fas fa-lightbulb text-xl"></i>
                    </div>
                    <h2 class="text-2xl font-bold">关键要点总结</h2>
                </div>
                <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                    <div class="bg-white p-6 rounded-lg shadow-sm">
                        <h3 class="font-bold mb-3 text-lg">核心组件</h3>
                        <ul class="space-y-2">
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                <span><code class="font-mono">Transaction</code>接口定义事务基本操作</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                <span><code class="font-mono">TransactionFactory</code>负责创建事务实例</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                <span><code class="font-mono">JdbcTransaction</code>是默认的JDBC实现</span>
                            </li>
                        </ul>
                    </div>
                    <div class="bg-white p-6 rounded-lg shadow-sm">
                        <h3 class="font-bold mb-3 text-lg">最佳实践</h3>
                        <ul class="space-y-2">
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                <span>根据应用场景选择合适的事务隔离级别</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                <span>企业级应用推荐使用Spring集成方案</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                <span>确保事务的及时关闭以释放资源</span>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </section>
    </main>

    <!-- Footer -->
    <footer class="footer text-white py-8">
        <div class="container mx-auto max-w-5xl px-4 md:px-0">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-4 md:mb-0">
                    <h3 class="text-xl font-bold">技术小馆</h3>
                    <p class="text-gray-400 mt-1">深入解析技术原理，助力开发者成长</p>
                </div>
                <div>
                    <a href="http://www.yuque.com/jtostring" class="text-blue-300 hover:text-white transition duration-300">
                        <i class="fas fa-globe mr-2"></i>http://www.yuque.com/jtostring
                    </a>
                </div>
            </div>
        </div>
    </footer>

    <!-- Mermaid Initialization -->
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
    </script>
</body>
</html>
```